var express = require('express');
var router = express.Router();
var path = require('path');
const { use } = require('./users');
var sqlite3 = require('sqlite3').verbose();

/* GET home page. */
router.get('/', function(req, res, next) {
  //http://localhost:3000/main11.html?sx=1&reason1=1&gn=2&reason2=2&jg=3&reason3=3&sp=4&reason4=4&xx=5&reason5=5&sj=1&ll=2&zg=3&sxcd=3
  var username=req.query.username;
  console.log("username:",username)
  var sx=req.query.sx;
  sx=sx.toString()
  var r1=req.query.reason1;
  r1=r1.toString()
  var r2=req.query.reason2;
  r2=r2.toString()
  var r3=req.query.reason3;
  r3=r3.toString()
  var r4=req.query.reason4;
  r4=r4.toString()
  var r5=req.query.reason5;
  r5=r5.toString()
  var gn=req.query.gn;
  gn=gn.toString()
  var jg=req.query.jg;
  jg=jg.toString()
  var sp=req.query.sp;
  sp=sp.toString()
  var xx=req.query.xx;
  xx=xx.toString()
  var sj=req.query.sj;
  sj=sj.toString()
  var ll=req.query.ll;
  ll=ll.toString()
  var zg=req.query.zg;
  zg=zg.toString()
  var sxcd=req.query.sxcd;
  sxcd=sxcd.toString()
  var kk;
  console.log("aaa",sx,gn,jg,sp,xx,sj,ll,zg,sxcd,r1,r2,r3,r4,r5)
  var db=new sqlite3.Database(path.join(__dirname,"../public/db/data.s3db"));
  kk=__dirname;
/*
  db.run(`create table fancy1 (user VARCHAR,wt VARCHAR,answer VARCHAR)`, function(
    err
  ) {
    if (err) throw err;
    console.log("Create Table Success!");
  });*/
    //sqlStr1="UPDATE `no3` SET answer = r1 WHERE user = 'zj1' and wt = 'r1'"
  /*
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",sx,username,"sx");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",gn,username,"gn");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",jg,username,"jg");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",sp,username,"sp");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",xx,username,"xx");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",sj,username,"sj");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",ll,username,"ll");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",zg,username,"zg");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",sxcd,username,"sxcd");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",r1,username,"r1");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",r2,username,"r2");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",r3,username,"r3");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",r4,username,"r4");
  db.run("UPDATE no1 SET answer = ? WHERE user = ? and wt = ?",r5,username,"r5");
  */


  db.run("insert into no2 values (?,?,?)",username,"sx",sx);
  db.run("insert into no2 values (?,?,?)",username,"gn",gn);
  db.run("insert into no2 values (?,?,?)",username,"jg",jg);
  db.run("insert into no2 values (?,?,?)",username,"sp",sp);
  db.run("insert into no2 values (?,?,?)",username,"xx",xx);
  db.run("insert into no2 values (?,?,?)",username,"sj",sj);
  db.run("insert into no2 values (?,?,?)",username,"ll",ll);
  db.run("insert into no2 values (?,?,?)",username,"zg",zg);
  db.run("insert into no2 values (?,?,?)",username,"sxcd",sxcd);
  db.run("insert into no2 values (?,?,?)",username,"r1",r1);
  db.run("insert into no2 values (?,?,?)",username,"r2",r2);
  db.run("insert into no2 values (?,?,?)",username,"r3",r3);
  db.run("insert into no2 values (?,?,?)",username,"r4",r4);
  db.run("insert into no2 values (?,?,?)",username,"r5",r5);

    //var r=db.prepare(`UPDATE no3 SET answer = ? WHERE user = ? and wt = ?`,r1,"zj1","r1");
    //r.exec();
  db.close(function(err){
    if (err) throw err;
  })
  res.render('TJ', { title: '提交成功' });
});

module.exports = router;
